/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.dao;

import static cn.org.rapid_framework.util.ObjectUtils.isNotEmpty;

import java.util.HashMap;
import java.util.Map;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

import com.tech15.pub.model.EmployeeDemand;
import com.tech15.pub.vo.query.EmployeeDemandQuery;

@Repository
public class EmployeeDemandDao extends BaseHibernateDao<EmployeeDemand,Long>{

	public Class getEntityClass() {
		return EmployeeDemand.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from EmployeeDemand t where 1=1 "
				+ "/~ and t.zt = '[zt]' ~/"
				+ "/~ and t.nr = '[nr]' ~/"
				+ "/~ and t.ygid = '[ygid]' ~/"
				+ "/~ and t.sqrq = '[sqrq]' ~/"
				+ "/~ and t.sqzt = '[sqzt]' ~/"
				+ "/~ and t.hfnr = '[hfnr]' ~/"
				+ "/~ and t.lb = '[lb]' ~/"
				+ "/~ and t.hfrq = '[hfrq]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(EmployeeDemandQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t.*,t1.name as dataname,t2.username from Employee_Demand t " +
				" left join pub_data t1 on t.lb=t1.id " +
				" left join sys_user t2 on t.ygid=t2.userid where 1=1 "
				+ "/~ and t.zt like '%[zt]%' ~/"
				+ "/~ and t.nr = '[nr]' ~/"
				+ "/~ and t.ygid = '[ygid]' ~/"
				+ "/~ and t.sqrq = '[sqrq]' ~/"
				+ "/~ and t.sqzt = '[sqzt]' ~/"
				+ "/~ and t.hfnr = '[hfnr]' ~/"
				+ "/~ and t.lb = '[lb]' ~/"
				+ "/~ and t.hfrq = '[hfrq]' ~/"
				+ "/~ order by [sortColumns] ~/";
		Map map = new HashMap();
		map.put("id","Long");
		map.put("zt","String");
		map.put("nr","String");
		map.put("ygid","Long");
		map.put("sqzt","Integer");
		map.put("sqrq","Timestamp");
		map.put("hfrq","Timestamp");
		map.put("lb","Long");
		map.put("hfnr","String");
		map.put("dataname","String");
		map.put("username","String");
		return pageSqlQuery(sql,query, map, EmployeeDemand.class);
	}
	

}
